package model

import (
	"time"
)

// User 用户模型
type User struct {
	ID        string    `json:"id" gorm:"primaryKey"`
	Username  string    `json:"username" gorm:"uniqueIndex;not null"`
	Email     string    `json:"email" gorm:"uniqueIndex;not null"`
	Password  string    `json:"-" gorm:"not null"` // 密码不在JSON中返回
	Avatar    string    `json:"avatar"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	LastLogin time.Time `json:"last_login"`
	IsActive  bool      `json:"is_active" gorm:"default:true"`
}

// UserRegisterRequest 用户注册请求
type UserRegisterRequest struct {
	Username string `json:"username" binding:"required,min=3,max=20"`
	Email    string `json:"email" binding:"required,email"`
	Password string `json:"password" binding:"required,min=6"`
}

// UserLoginRequest 用户登录请求
type UserLoginRequest struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

// UserLoginResponse 用户登录响应
type UserLoginResponse struct {
	User  User   `json:"user"`
	Token string `json:"token"`
}

// UserProfile 用户资料
type UserProfile struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Avatar   string `json:"avatar"`
}

// UserUpdateRequest 用户更新请求
type UserUpdateRequest struct {
	Username string `json:"username,omitempty" binding:"omitempty,min=3,max=20"`
	Email    string `json:"email,omitempty" binding:"omitempty,email"`
	Avatar   string `json:"avatar,omitempty"`
}

// ChangePasswordRequest 修改密码请求
type ChangePasswordRequest struct {
	OldPassword string `json:"old_password" binding:"required"`
	NewPassword string `json:"new_password" binding:"required,min=6"`
}

// Session 会话模型
type Session struct {
	ID        string    `json:"id" gorm:"primaryKey"`
	UserID    string    `json:"user_id" gorm:"not null;index"`
	Token     string    `json:"token" gorm:"uniqueIndex;not null"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
	IsActive  bool      `json:"is_active" gorm:"default:true"`
}

// UserFile 用户文件模型
type UserFile struct {
	ID        string    `json:"id" gorm:"primaryKey"`
	UserID    string    `json:"user_id" gorm:"not null;index"`
	Name      string    `json:"name" gorm:"not null"`
	Path      string    `json:"path" gorm:"not null"`
	Content   string    `json:"content"`
	Size      int64     `json:"size"`
	MimeType  string    `json:"mime_type"`
	IsFolder  bool      `json:"is_folder" gorm:"default:false"`
	ParentID  string    `json:"parent_id" gorm:"index"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

// UserFileRequest 用户文件操作请求
type UserFileRequest struct {
	Name     string `json:"name" binding:"required"`
	Content  string `json:"content,omitempty"`
	IsFolder bool   `json:"is_folder,omitempty"`
	ParentID string `json:"parent_id,omitempty"`
}

// UserFileResponse 用户文件响应
type UserFileResponse struct {
	ID        string                `json:"id"`
	Name      string                `json:"name"`
	Path      string                `json:"path"`
	Size      int64                 `json:"size"`
	MimeType  string                `json:"mime_type"`
	IsFolder  bool                  `json:"is_folder"`
	ParentID  string                `json:"parent_id"`
	Children  []UserFileResponse    `json:"children,omitempty"`
	CreatedAt time.Time             `json:"created_at"`
	UpdatedAt time.Time             `json:"updated_at"`
}